#include "Novel.hpp"

int main()
{

  try
  {
    // 创建Mapper实例
    NovelMapper mapper("tcp://112.74.40.147:3306", "root", "Ahqjhqj73@you", "novel_db");

    // 插入新小说
    Novel newNovel{
        0, // id由数据库生成
        "The Great Novel",
        1001,
        NovelStatus::ONGOING,
        300,
        "Fantasy",
        35,
        250};

    int newId = mapper.insertNovel(newNovel);
    std::cout << "Inserted ID: " << newId << std::endl;

    // 查询小说
    Novel novel = mapper.getNovelById(newId);
    std::cout << "Novel Name: " << novel._name << novel._author_id<<novel._count_page<<novel._type<<novel._count_chapter<<novel._count_ticket<< std::endl;

    // 更新小说
    novel._count_ticket = 300;
    mapper.updateNovel(novel);

    // 查询作者的所有作品
    auto authorNovels = mapper.getNovelsByAuthor(1001);

    // 查询完结小说
    auto completedNovels = mapper.getNovelsByStatus(NovelStatus::COMPLETED);

    // 删除小说
    mapper.deleteNovel(newId);
  }
  catch (sql::SQLException &e)
  {
    std::cerr << "SQL Error: " << e.what() << std::endl;
  }
}

